import {WIDGET_TYPE} from './widget-const.js';
import HTMLWidget from './html-widget.js'
import MarkdownWidget from './markdown-widget.js'
import TableWidget from './table-widget.js'
import ImageWidget from './image-widget.js'
import ScriptWidget from './script-widget.js'
import TextWidget from './text-widget.js'
import TODOWidget from './todo-widget.js'
import CodeWidget from './code-widget.js'
import QuoteWidget from './quote-widget.js'
import MathWidget from './math-widget.js'

let _mapWidgetClasses = new Map();

export default function CreateWidget(type, sectionData, dispatcher) {
    const _cls = _mapWidgetClasses.get(type);
    if(_cls) {
        return new _cls(sectionData, dispatcher);
    } else return new TextWidget(sectionData, dispatcher);
}

/// init;
(function () {
    _mapWidgetClasses.set(WIDGET_TYPE.HTML, HTMLWidget);
    _mapWidgetClasses.set(WIDGET_TYPE.MARKDOWN, MarkdownWidget);
    _mapWidgetClasses.set(WIDGET_TYPE.TABLE, TableWidget);
    _mapWidgetClasses.set(WIDGET_TYPE.IMAGE, ImageWidget);
    _mapWidgetClasses.set(WIDGET_TYPE.SCRIPT, ScriptWidget);
    _mapWidgetClasses.set(WIDGET_TYPE.TODO, TODOWidget);
    _mapWidgetClasses.set(WIDGET_TYPE.TEXT, TextWidget);
    _mapWidgetClasses.set(WIDGET_TYPE.CODE, CodeWidget);
    _mapWidgetClasses.set(WIDGET_TYPE.QUOTE, QuoteWidget);
    _mapWidgetClasses.set(WIDGET_TYPE.MATH, MathWidget);
})();

